<template>
  <div class="index-container">
    <div class="main-header clearfix">
      <el-row>
       <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
          <!-- <el-button type="primary"  icon="el-icon-plus" class="sureBtn"  size="medium"  @click="handleAdd" > 新 增 设 备</el-button> -->
           <span style="color: transparent;">1</span>
        </el-col>
        <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
          <div class="search fr">
            <div>
              <el-input  v-model="searchForm.name"   size="medium"  placeholder="礼品名称"></el-input>
            </div>
            <div>
              <el-select v-model="searchForm.type" clearable @clear="clear" @change="clear" placeholder="请选择变动类型">
                <el-option label="入库" value="1"></el-option>
                <el-option label="分配" value="2"></el-option>
                <el-option label="损耗" value="4"></el-option>
              </el-select>
            </div>
            <el-button size="medium"   type="primary"   icon="el-icon-search"  class="fr"    @click="onSearch" > 搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="main-content" style="height: calc(100vh - 250px);">
      <main-table
        :columns="tableColumns"
        :data="tableList"
        :loading="loading"
        :pagination="pagination"
        @getData="fetchTableList"
        wrapperHeight="calc(100% - 73px)" height="100%"
      >
      <el-table-column slot="num" label="变动数量" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.type == '1'" :style="{'color': '#67c23a'}">{{ scope.row.num }}</span>
          <span v-else-if="scope.row.type == '2'" :style="{'color': '#ff9800'}">{{ scope.row.num }}</span>
          <span v-else-if="scope.row.type == '3'" :style="{'color': '#409EFF'}">{{ scope.row.num }}</span>
          <span v-else-if="scope.row.type == '4'" :style="{'color': '#f56c6c'}">{{ scope.row.num }}</span>
        </template>
      </el-table-column>
      <el-table-column slot="type" label="变动类型" align="center">
        <template slot-scope="scope">
           <span v-if="scope.row.type == '1'" style="color: #67c23a;"> 入库 </span>
           <span v-else-if="scope.row.type == '2'" style="color: #ff9800;"> 分配 </span>
           <span v-else-if="scope.row.type == '3'" style="color: #409EFF;"> 兑换 </span>
           <span v-else-if="scope.row.type == '4'" style="color: #f56c6c;"> 损耗 </span>
        </template>
      </el-table-column>

      </main-table>
    </div>
  </div>
</template>
<script>
  import mainTable from "@/components/main-table/index";
  import * as APIIntegral from '@/api/integral'
  import { sex, age, elderlyCategory, sourceType, unixToDate, faceFailed } from "@/utils";
  export default {
    name: "helpManager-integral-goods-log",
    components: {
      mainTable
    },
    data() {
      return {
        loading: false,
        title: '添加图标',
        dialogVisible: false,
        dialogImageVisible: false,
        dialogImageUrl:'',
        ruleForm: {},
        searchForm: {
          page: 1
        },
        tableList:[],
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        tableColumns: [
         {
           index: true,
           fixed: true
         },
         {
           prop: 'name',
           label: '礼品名称'
         },
         {
           prop: 'danwei',
           label: '单位'
         },
         {
           prop: 'guige',
           label: '规格'
         },
         {
           slot: 'type'
         },
         {
           slot: 'num'
         },
         {
           prop: 'a_name',
           label: '分配站点'
         },
         {
           prop: 'msg',
           label: '备注'
         },
         {
           prop: 'create_time',
           label: '操作时间',
           width: 200,
           formatter (row, column, cellValue) {
             return unixToDate(cellValue)
           }
         },
         {
           prop: 'admin_name',
           label: '操作员工'
         }
        ],
        key: Math.random(),
      };
    },
    created() {},
    beforeDestroy() {},
    mounted() {
      this.fetchTableList();
    },
    methods: {
      // 点击”查询“按钮 => 此时缓存查询参数
      onSearch () {
        this.pagination = {
          current: 1,
          size: 10,
          total: 0
        }
        this.fetchTableList()
      },
      load () {
        this.fetchTableList()
      },
      // 手动清空/搜索
      clear () {
        this.fetchTableList({ page: 1 })
      },
      fetchTableList(pageObj) {
        this.loading = true
        this.searchForm = {
          ...this.searchForm,
          ...pageObj
        }
        APIIntegral.integralGoodslog(this.searchForm).then((resp) => {
          if (resp.code == 200) {
            const { list = [], total = 0 } = resp.data;
            this.tableList = list || []
            this.pagination.total = total;
          }
        }).finally(() => {
         this.loading = false
        });
      },
    },
  };
</script>
<style lang="scss" scoped>
  .index-container {
    box-sizing: border-box;
    width: 100%;
    padding: 0 30px !important;
    margin: 0 !important;
    background: #fff !important;

    .main-header {
      padding-top: 4px;
      margin-bottom: 24px;

      .search {
        display: inline-block;

        .search-title {
          flex: 0 0 48px;
          width: 48px;
          font-size: 16px;
          line-height: 36px;
          color: #333;
        }
      }

      .search > div {
        display: inline-block;
        margin-left: 20px;
      }
    }
    .task-icon-img{
      width: 80px;
      height: 80px;
    }
  }

  .form-footer {
    padding-left: 100px;
  }

  .dialog-main {
    .table-do {
      margin-bottom: 15px;
    }

    ::v-deep {
      th {
        .cell {
          color: #fff;
        }
      }
    }
  }
</style>
